/*
 * Copyright (C) 2021, All rights Reserved, Designed By
 * @author: maoyz
 * @Copyright: 2021-02-24 10:16  Inc. All rights reserved.
 */
package com.myz.cloud.stream.rocketmq.error.producer.consumer;

import com.myz.cloud.stream.rocketmq.error.producer.channel.IErrorMessageChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

/**
 * @author maoyz
 */
@Component
@EnableBinding({IErrorMessageChannel.class})
public class ErrorMessageConsumer {

    private static final Logger log = LoggerFactory.getLogger(ErrorMessageConsumer.class);

    @StreamListener(IErrorMessageChannel.ERROR_1_INPUT)
    public void receive(String msg) {
        log.info("{} receive {}", IErrorMessageChannel.ERROR_1_INPUT, msg);
        throw new RuntimeException("error1");
    }

    /**
     * inputChannel = topicName.errors
     *
     * @param message
     */
    @ServiceActivator(inputChannel = "error-topic-1.errors")
    public void se(Message message) {
        log.error("topicName.errors={}", message);
    }
}